﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Markdown
{
    /// <summary>
    /// 表示解析帧栈
    /// </summary>
    internal class AmlParseFrameStack
    {
        Stack<AmlParseFrame> m_stack;

        public AmlParseFrameStack()
        {
            m_stack = new Stack<AmlParseFrame>();
        }

        /// <summary>
        /// 弹出栈顶元素并返回
        /// </summary>
        /// <returns>返回栈顶元素</returns>
        public AmlParseFrame Pop()
        {
            return m_stack.Pop();
        }

        /// <summary>
        /// 获取栈顶元素
        /// </summary>
        /// <returns>返回栈顶元素</returns>
        public AmlParseFrame Peek()
        {
            return m_stack.Peek();
        }

        /// <summary>
        /// 将一个解析帧放入当前栈中
        /// </summary>
        /// <param name="frame">指定的栈帧</param>
        public void Push(AmlParseFrame frame)
        {
            m_stack.Push(frame);
        }

        /// <summary>
        /// 清空当前栈
        /// </summary>
        public void Clear()
        {
            m_stack.Clear();
        }

        /// <summary>
        /// 获取当前解析帧栈的元素个数
        /// </summary>
        public int Count {
            get { return m_stack.Count; }
        }

        /// <summary>
        /// 返回当前堆栈是否为空
        /// </summary>
        public bool IsEmpty {
            get { return m_stack.Count == 0; }
        }

        /// <summary>
        /// 获取与当前对象等价的字符串形式
        /// </summary>
        /// <returns>返回与当前对象等价的字符串形式</returns>
        public override string ToString()
        {
            return $"count:{m_stack.Count}";
        }
    }
}
